<template>
  <div class="generalPurposeDebugger">
    <!-- <img class="banner" src="../assets/generalPurposeDebugger.png" alt="" />
     -->
     <img class="sane" v-if="list.bannerImgUrl" :src="list.bannerImgUrl" alt="" />
    <img class="sane" v-if="list.detailImgUrl" :src="list.detailImgUrl" alt="" />
    <div class="list">

      <div  class="item" :key="index" v-for="(item, index) in list.productBusVos">
        <div @click="detail(item)" class="title">{{item.productName}}</div>
        <div class="imgs">
          <img @click="detail(item)"  :src="item.primaryUrl" alt="" />
          
          <!-- <div v-else class="no">
            <div>即将发布</div>
            <div>敬请期待</div>
          </div> -->
        </div>
        <div class="handle">
          <!-- <span @click="addgwcartFn(info)">添加至清单</span> -->

          <!-- <span v-if="item.pdfUrl" v-down="{
           url:item.pdfUrl,
           type:'PDF下载',
           name:item.productName
          }"> -->

          <span v-if="item.pdfUrl" 
          @click="downFn(item.pdfOssId)"
          >
          PDF下载</span>
          <!-- <span
          v-if="item.threedUrl"
          v-down="{
           url:item.threedUrl,
           type:'3D模型下载',
           name:item.productName
          }"
            > -->

          <span
          v-if="item.threedUrl"
          @click="downFn(item.threedOssId)"
            >3D模型下载</span
          >
        </div>
      </div>
    </div>
    <cart :curId="curId" :sendInfo="sendInfo" @showCartFn="showCartFn" v-if="showCartFlag" />
 
  </div>
</template>

<script>
import cart from './cart/index.vue'
import "../utils/vdown";
import { getproductlist } from "../apis/index";
export default {
  name: "generalPurposeDebugger",
  components: {cart},
  data() {
    return {
      curId:'',
      sendInfo:{},
      showCartFlag:false,
      info:{},
      list:[]
    };
  },
  computed: {},
  created() {
    this.getDetai();
  },
  methods: {
    showCartFn(){
      this.showCartFlag = false
    }, 
    addgwcartFn(item) {
      console.log(item, 555);
      this.curId = item.id;
      this.showCartFlag = true

    },
    downFn(url) {
      console.log(url,'rrrrrrrrrrrr');

      this.$download.oss(url)
      // this.downLoadFile(url);

        // this.download(`system/oss/download/${ossid}`, {
      // }, `${name}.xlsx`)
      
    },
    downLoadFile(url) {
      let fileName = url.slice(url.lastIndexOf("/") + 1); // 这里是通过从后端获取到的 url  地址中截出来原本的文件名
      fetch(url)
        .then((res) => res.blob())
        .then((blob) => {
          const link = document.createElement("a");
          link.href = URL.createObjectURL(blob);
          // 下载文件的名称及文件类型后缀
          link.download = fileName;
          document.body.appendChild(link);
          link.click();
          //在资源下载完成后 清除 占用的缓存资源
          window.URL.revokeObjectURL(link.href);
          document.body.removeChild(link);
        });
    },

    detail(item) {
      this.$router.push({
        path: "/detail?id="+item.id,
      });
    },
    getDetai() {
      getproductlist({ nameType: this.$route.query.nameType })
        .then((res) => {
          console.log(res.data.data, 88888888888);
          this.list = res.data.data
        })

        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.generalPurposeDebugger {
  .sane{
    display: block;
    width: 100%;
  }
  .banner {
    display: block;
    width: 100%;
  }

  .list {
    width: 1420px !important;
    margin: 108px auto;
    display: flex;
    flex-wrap: wrap;
    .item {
      width: 32%;
      margin-right: 2%;
      margin-bottom: 36px;
      &:nth-child(3n) {
        margin-right: 0;
      }
    }
    .title {
      width: 100%;
      height: 40px;
      background: url("../assets/123.jpg") no-repeat;
      background-size: 100% 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #fff;
      font-weight: bold;
    }
    .imgs {
      border: 1px solid #2a2c2e;
      // width: 100%;
      height: 450px;
      img {
        display: block;
        width: 100%;
        height: 450px;
      }
      .no {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 100%;
        width: 100%;
        background: #2a2c2e;
        color: #fff;
        font-weight: bold;
        font-size: 18px;
        line-height: 30px;
      }
    }
    .handle {
      display: flex;
      justify-content: space-between;
      padding: 10px 40px;
      span {
        font-family: FZLTZHK--GBK1, FZLTZHK--GBK1;
        cursor: pointer;
        text-decoration: underline;
        color: #2a2c2e;
        font-size: 16px;
        &:last-child {
          margin-right: 0;
        }
      }
    }
  }
}
</style>